package com.ruoyi.returnMaterials.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.returnMaterials.domain.ErpProductionReturnMaterial;
import com.ruoyi.returnMaterials.service.IErpProductionReturnMaterialService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 生产退料Controller
 * 
 * @author ruoyi
 * @date 2025-07-30
 */
@RestController
@RequestMapping("/returnMaterials/returnMaterials")
public class ErpProductionReturnMaterialController extends BaseController
{
    @Autowired
    private IErpProductionReturnMaterialService erpProductionReturnMaterialService;

    /**
     * 查询生产退料列表
     */
    @PreAuthorize("@ss.hasPermi('returnMaterials:returnMaterials:list')")
    @GetMapping("/list")
    public TableDataInfo list(ErpProductionReturnMaterial erpProductionReturnMaterial)
    {
        startPage();
        List<ErpProductionReturnMaterial> list = erpProductionReturnMaterialService.selectErpProductionReturnMaterialList(erpProductionReturnMaterial);
        return getDataTable(list);
    }

    /**
     * 导出生产退料列表
     */
    @PreAuthorize("@ss.hasPermi('returnMaterials:returnMaterials:export')")
    @Log(title = "生产退料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ErpProductionReturnMaterial erpProductionReturnMaterial)
    {
        List<ErpProductionReturnMaterial> list = erpProductionReturnMaterialService.selectErpProductionReturnMaterialList(erpProductionReturnMaterial);
        ExcelUtil<ErpProductionReturnMaterial> util = new ExcelUtil<ErpProductionReturnMaterial>(ErpProductionReturnMaterial.class);
        util.exportExcel(response, list, "生产退料数据");
    }

    /**
     * 获取生产退料详细信息
     */
    @PreAuthorize("@ss.hasPermi('returnMaterials:returnMaterials:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(erpProductionReturnMaterialService.selectErpProductionReturnMaterialById(id));
    }

    /**
     * 新增生产退料
     */
    @PreAuthorize("@ss.hasPermi('returnMaterials:returnMaterials:add')")
    @Log(title = "生产退料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ErpProductionReturnMaterial erpProductionReturnMaterial)
    {
        return toAjax(erpProductionReturnMaterialService.insertErpProductionReturnMaterial(erpProductionReturnMaterial));
    }

    /**
     * 修改生产退料
     */
    @PreAuthorize("@ss.hasPermi('returnMaterials:returnMaterials:edit')")
    @Log(title = "生产退料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ErpProductionReturnMaterial erpProductionReturnMaterial)
    {
        return toAjax(erpProductionReturnMaterialService.updateErpProductionReturnMaterial(erpProductionReturnMaterial));
    }

    /**
     * 删除生产退料
     */
    @PreAuthorize("@ss.hasPermi('returnMaterials:returnMaterials:remove')")
    @Log(title = "生产退料", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(erpProductionReturnMaterialService.deleteErpProductionReturnMaterialByIds(ids));
    }
}
